/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

/**
 *
 * @author Declan
 */
@Entity
@NamedQueries({
    @NamedQuery(
        name = "findPhoneByManufacturerAndMake",
        query = " SELECT p" +
                " FROM Phone p" +
                " WHERE LOWER(p.manufacturer) = LOWER(:entry)" +
                " OR LOWER(p.make) = LOWER(:entry)" +
                " ORDER BY p.price"
    )
})
@DiscriminatorValue("PHONE")
public class Phone extends Product implements Serializable {
    
    private String make;
    //private float price;
    private String manufacturer;
    private float weight;
    @OneToMany
    private Collection<Contract> availableContracts;


    public String getMake()             { return make; }
    public void setMake(String make)    { this.make = make; }
    public String getManufacturer()     { return manufacturer; }
    public void setManufacturer(String manufacturer)
        { this.manufacturer = manufacturer; }
    public float getWeight()            { return weight; }
    public void setWeight(float weight) { this.weight = weight; }
    @Override
    public String getName()             { return manufacturer + " " + make; }

    public Phone(double price, String manufacturer, String make,  float weight)
    {
        this.make = make;
        this.price = price;
        this.manufacturer = manufacturer;
        this.weight = weight;
    }

    public Phone() {}

    @Override
    public String toString() {
        return "model.PhoneEntity[manufacturer=" + manufacturer + "]\n" +
               "model.PhoneEntity[make=" + make + "]\n" +
               "model.PhoneEntity[price=" + price + "]\n" +
               "model.PhoneEntity[weight=" + weight + "]\n";
    }

}
